package com.twu.biblioteca;

import java.util.HashMap;
import java.util.Map;

public class Userstore {

    private static final Userstore instance = new Userstore();

    private Map<String, User> users;
    private User currentUser;

    private Userstore() {
        this.users = new HashMap<String, User>();
        users.put("111-1111", new User("John", "john@gmail.com", "08011233", "111-1111", "123"));
        users.put("222-2222", new User("Tim", "john@gmail.fr", "092032012", "222-2222", "123"));
        users.put("333-3333", new User("Leo", "leo@gmail.hk", "01025965", "333-3333", "123"));
    }

    public static Userstore getInstance() {
        return instance;
    }

    public boolean login(String loginnumber, String password) {
        User user = users.get(loginnumber);

        if (user != null && password.equals(user.getPassword())) {
            this.currentUser = user;
            return true;
        }
        this.currentUser = null;
        return false;
    }

    public User getCurrentUser() {
        return this.currentUser;
    }

}
